{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T05:45:55.245434Z",
     "start_time": "2025-06-25T05:45:52.907114Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_ollama import ChatOllama\n",
    "from langchain_core.messages import HumanMessage, SystemMessage\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "\n",
    "from jupyter_constants import OLLAMA_PROMPT_TEMPLATE_NOTHINK, OLLAMA_DEFAULT_MODEL\n",
    "\n",
    "ollama = ChatOllama(model=OLLAMA_DEFAULT_MODEL, temperature=0.5)\n",
    "\n",
    "prompt = ChatPromptTemplate.from_template(OLLAMA_PROMPT_TEMPLATE_NOTHINK)\n",
    "\n",
    "chat = prompt | ollama"
   ],
   "id": "e0869ac0733b8ad5",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-25T05:47:21.323908Z",
     "start_time": "2025-06-25T05:45:55.246465Z"
    }
   },
   "cell_type": "code",
   "source": [
    "messages = [\n",
    "    SystemMessage(\"接下来，你需要将解题思路分解成多个STEP，将每一步放在<step-?>...</step-?>之间输出，?表示第几步。\"),\n",
    "    HumanMessage(\"如何制作提拉米苏?\"),\n",
    "]\n",
    "\n",
    "for chuck in chat.stream(messages):\n",
    "    print(chuck.content, end=\"\", flush=True)"
   ],
   "id": "4e7388253b73e28c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<think>\n",
      "\n",
      "</think>\n",
      "\n",
      "<step-1> 准备材料：提拉米苏的主要材料包括马斯卡彭奶酪、鸡蛋、糖、咖啡液、可可粉和手指饼干。</step-1>\n",
      "\n",
      "<step-2> 制作咖啡液：将浓缩咖啡与少量糖混合，搅拌至糖完全溶解，制成咖啡液。</step-2>\n",
      "\n",
      "<step-3> 打发奶油和奶酪：将鸡蛋黄与糖混合，搅拌至颜色变浅，然后加入马斯卡彭奶酪，搅拌均匀。接着，将蛋清打发至硬性发泡，分次加入奶酪混合物中，轻轻搅拌均匀。</step-3>\n",
      "\n",
      "<step-4> 混合手指饼干：将手指饼干浸泡在咖啡液中，使其吸收部分咖啡液，然后铺在容器底部。</step-4>\n",
      "\n",
      "<step-5> 层叠制作：在手指饼干上铺一层奶酪混合物，再撒上一层可可粉，重复此步骤，直到材料用完。</step-5>\n",
      "\n",
      "<step-6> 冷藏定型：将制作好的提拉米苏放入冰箱冷藏至少4小时，使其凝固和风味融合。</step-6>\n",
      "\n",
      "<step-7> 装饰与享用：取出后撒上额外的可可粉或巧克力碎，用刀切成块，即可享用。</step-7>"
     ]
    }
   ],
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
